package com.rongshu.view.userInfo.decoration;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.utils.MeasureUtils;

public class SpacesItemDecoration extends RecyclerView.ItemDecoration {

    private Context mContext = null;
    private int delta, delta_bottom;

    public SpacesItemDecoration(Context context) {
        this.mContext = context;
        delta = MeasureUtils.dp2px(mContext, 0.5f);
        delta_bottom = MeasureUtils.dp2px(mContext, 0.5f);
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int position = parent.getChildAdapterPosition(view);
        if (position % 3 == 0) {
            outRect.left = 0;
            outRect.right = delta;
            outRect.bottom = delta_bottom;
        } else if (position % 3 == 1) {
            outRect.left = 0;
            outRect.right = delta;
            outRect.bottom = delta_bottom;
        } else if (position % 3 == 2) {
            outRect.left = 0;
            outRect.right = 0;
            outRect.bottom = delta_bottom;
        }
    }
}
